package com.boyaa.shells.tool 
{
	import com.boyaa.shells.control.LayerManager;
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * MC悬浮提示，
	 * @author Fly
	 */
	public class Suspendedtip 
	{
		private var _mc:InteractiveObject;
		private var _tipStr:String = "";
		private var _tipMC:Sprite = null;
		
		public function Suspendedtip(mc:InteractiveObject, str:String)
		{
			_mc = mc;
			_tipStr = str;
		}
		
		
		public function addEvent():void
		{
			_mc.mouseEnabled = true;
			_mc.addEventListener(MouseEvent.ROLL_OVER, onTip);
			_mc.addEventListener(MouseEvent.ROLL_OUT, onTip);
			_mc.addEventListener(MouseEvent.MOUSE_MOVE, onTip);
		}
		
		public function removeEvent():void
		{
			_mc.removeEventListener(MouseEvent.ROLL_OVER, onTip);
			_mc.removeEventListener(MouseEvent.MOUSE_MOVE, onTip);
			_mc.removeEventListener(MouseEvent.ROLL_OUT, onTip);
		}
		
		public function changeTip(str:String):void
		{
			_tipStr = str;
		}
		private function onTip(e:MouseEvent):void 
		{
			if (e.type == MouseEvent.ROLL_OVER || e.type == MouseEvent.MOUSE_MOVE)
			{
				if (_tipMC != null)
				{
					_tipMC.parent && _tipMC.parent.removeChild(_tipMC);
					_tipMC = null;
				}
				_tipMC = new Sprite();
				var tf:TextField = new TextField();
				tf.multiline = true
				tf.htmlText = _tipStr;
				tf.width = tf.textWidth + 4;
				tf.height = tf.textHeight + 4;
				_tipMC.addChild(tf);
				tf.x = - tf.width / 2;
				tf.y = - tf.height / 2;
				_tipMC.x = e.stageX;
				if (e.stageY < 100)
					_tipMC.y = e.stageY + 40;
				else
					_tipMC.y = e.stageY - 40;
				_tipMC.addChildAt(Draw.drawRoundRect(_tipMC.width + 8, _tipMC.height + 8, 10, 10, 0xFFFFFF, 0x645433), 0);
				LayerManager.instance.addToLayer(LayerManager.textTipsLayer, _tipMC);
			}
			else
			{
				_tipMC.parent && _tipMC.parent.removeChild(_tipMC);
				_tipMC = null;
			}
		}
	}

}